/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sands;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

/**
 *
 * @author Admin
 */
public class NewNemoActivity extends Activity implements View.OnClickListener{

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle icicle){
	super.onCreate(icicle);
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	setContentView(R.layout.new_nemo);
	Button cancel = (Button) findViewById(R.id.cancel);
	Button save = (Button) findViewById(R.id.save);
	cancel.setOnClickListener(this);
	save.setOnClickListener(this);
	// ToDo add your GUI initialization code here        
    }

    public void onClick(View view){
	if(view instanceof Button){
	    Button btn = (Button) view;
	    CharSequence text = btn.getText();
	    if(text.equals("Save")){
		DatabaseHelper helper = DatabaseHelper.getInstance(this);
		TextView t1 = (TextView) findViewById(R.id.txt_url);
		TextView t2 = (TextView) findViewById(R.id.txt_uname);
		TextView t3 = (TextView) findViewById(R.id.txt_pwd);
		String url = t1.getText().toString();
		String uname = t2.getText().toString();
		String pwd = t3.getText().toString();
		String res = helper.insertNemo(new Nemo(url, uname, pwd));
		Toast.makeText(NewNemoActivity.this, res, Toast.LENGTH_LONG).show();
		setResult(RESULT_OK);
	    }
	    else{
		Toast.makeText(NewNemoActivity.this, "Cancelled...", Toast.LENGTH_LONG).show();
		setResult(RESULT_CANCELED);
	    }
	    finish();
	}
    }
}
